<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script>
    window.onload = function () {
      let btn1 = document.querySelector('#btn1');
      let btn2 = document.querySelector('#btn2');
      let img1 = document.querySelector('#img1');
      btn1.onclick = async function () {
        //请求 txt
        let res = await fetch('data/1.txt');
        //解析
        let str = await res.text();
        console.log(str)


        //请求 txt
        let ress = await fetch('data/1.json');
        //解析
        let json = await ress.json();
        console.log(json)
      }

      btn2.onclick = async function () {
        let res = await fetch('data/1.png');

        let data = await res.blob()

        let url = URL.createObjectURL(data)
        img1.src = url



      }
    }
  </script>
</head>

<body>
  <input type="button" value="获取" id="btn1">
  <input type="button" value="获取图片" id="btn2">
  <img src="" id="img1">


</body>

</html>